import 'package:base_router_helper/base_router_helper.dart';
import 'package:dio_log/dio_log.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:package_model/event.dart';
import 'package:person_model_project/main/main_body.dart';
import 'package:user_data_model/router/account_router.dart';
import 'package:user_data_model/user_data_model.dart';

/**
 *
 * @ProjectName:    person_model_project
 * @ClassName:      main_page
 * @Description:    dart类作用描述
 * @Author:         孙浩
 * @QQ:             243280864
 * @CreateDate:     2021/1/31 9:48 PM
 */
class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage>
    with SingleTickerProviderStateMixin {
  GlobalKey infoKey = GlobalKey();
  double bottomHeight = 230.w;
  List<String> pageNameList = ["Main", "News"];
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: pageNameList.length, vsync: this);
    EventUtil.loginEvent.on<LoginType>().listen((event) {
      if(event == LoginType.login){
        UserDataPlugin.getUserDataFromLocal().then((value){
          print("工程主体收到用户组件登录消息登录后获取用户信息成功:${value.data.toJson().toString()}");
        });

      }
    });
  }

  @override
  Widget build(BuildContext context) {
    showDebugBtn(context);
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: false,
        elevation: 0,
        backgroundColor: Colors.transparent,
        title: TabBar(
            isScrollable: true,
            unselectedLabelColor: Colors.black,
            unselectedLabelStyle:
                TextStyle(fontSize: 32.sp, fontWeight: FontWeight.normal),
            labelStyle: TextStyle(fontSize: 40.sp, fontWeight: FontWeight.bold),
            labelColor: Colors.black,
            controller: _tabController,
            tabs: pageNameList
                .map((e) => Tab(
                      text: e,
                    ))
                .toList()),
        actions: [],
      ),
      body: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Positioned(
            child: TabBarView(
                controller: _tabController,
                children: pageNameList
                    .map((e) => e == "Main" ? MainBodyPage() : Container())
                    .toList()),
            top: 0,
            bottom: 220.w,
            left: 0,
            right: 0,
          ),
          AnimatedPositioned(
            child: Container(
              child: Column(
                children: [
                  Container(
                    height: 130.w,
                    child: Row(
                      children: [
                        GestureDetector(child:ClipRRect(
                          child: AspectRatio(
                            aspectRatio: 1,
                            child: Image.network(
                                "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1564429550,1659123573&fm=26&gp=0.jpg"),
                          ),
                          borderRadius: BorderRadius.circular(100),
                        ) ,onTap: (){
                          NavigationUtil.push2page(context, AccountRouter.loginByPwd);
                        },)

                      ],
                    ),
                  )
                ],
              ),
              margin: EdgeInsets.symmetric(horizontal: 10.w),
              decoration: BoxDecoration(
                  color: Colors.white,
                  boxShadow: [
                    BoxShadow(color: Colors.black12, blurRadius: 10.w)
                  ],
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(24.w),
                      topRight: Radius.circular(24.w))),
              padding:
                  EdgeInsets.symmetric(horizontal: 24.w).copyWith(top: 20.w),
            ),
            duration: Duration(seconds: 200),
            bottom: 0,
            left: 0,
            right: 0,
            height: bottomHeight,
            key: infoKey,
          )
        ],
      ),
    );
  }
}
